Total Complexity | 2 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { |
||
18 | |||
19 | @Controller('ingestions') |
||
20 | @ApiTags('Ingestion') |
||
21 | @ApiBearerAuth() |
||
22 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
23 | export class CreateFileIngestionAction { |
||
24 | constructor( |
||
25 | @Inject('ICommandBus') |
||
26 | private readonly commandBus: ICommandBus, |
||
27 | @Inject('IFileUpload') |
||
28 | private readonly fileUploadAdapter: IFileUpload |
||
29 | ) {} |
||
30 | |||
31 | @Post(':id/photos') |
||
32 | @Roles('photographer') |
||
33 | @ApiOperation({ |
||
34 | summary: |
||
35 | 'Create ingestion for a school, and return enpoint to upload files containing photos' |
||
36 | }) |
||
37 | public async index(@Param() idDto: IdDTO): Promise<SchoolUploadEndpointView> { |
||
38 | try { |
||
39 | const ingestionId = await this.commandBus.execute( |
||
40 | new CreateIngestionCommand(idDto.id) |
||
41 | ); |
||
42 | |||
43 | const url = await this.fileUploadAdapter.getEndPoint( |
||
44 | `upload/photo/${ingestionId}.zip` |
||
45 | ); |
||
46 | |||
47 | return new SchoolUploadEndpointView(url); |
||
48 | } catch (e) { |
||
49 | throw new BadRequestException(e.message); |
||
50 | } |
||
53 |